

package jetbrains.buildServer.server.rest.util;

import java.util.HashMap;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;

public class SimpleStringPool implements StringPool {
  private final HashMap<String, String> myStringPool = new HashMap<>();

  @Contract("null -> null, !null -> !null")
  public String reuse(@Nullable String value) {
    if (value == null) {
      return null;
    }

    String result = myStringPool.get(value);
    if (result == null) {
      myStringPool.put(value, value);

      return value;
    }

    return result;
  }
}